package modular.mapreduce;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 对象要进行网络传输必须进行序列化，jdk的原生序列化比较冗余，hadoop 设计了自己的
 *
 * @Author yuelinbo
 * @Date 2018/12/6 18:08
 **/
public class WordCountMapper extends Mapper<LongWritable, Text,Text, IntWritable> {


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        String line = value.toString();
        String[] words = line.split("\\$");
        for (String word:words){
            context.write(new Text(word),new IntWritable(1));
        }

    }
}
